package sort;

/**
 * @author RunningShrimp
 * @date 2021/6/9  13:36
 * @see <a href=""></a>
 */
public class SelectSort<E extends Comparable<E>> extends BaseSort<E> {
    @Override
    public void sort(E[] array) {
        for (int i = 0; i < array.length; i++) {
            int minIndex = i;
            for (int j = i + 1; j < array.length; j++) {
                if (less(array[minIndex], array[j])) {
                    minIndex = j;
                }
            }
            exchange(array, i, minIndex);
        }
    }

    public static void main(String[] args) {
        Integer[] array = BaseSort.generateArray(10000, 100000);
        BaseSort<Integer> sort = new SelectSort<>();
        System.out.println("排序前：");
        sort.show(array);
        sort.sort(array);
        System.out.println("排序后");
        sort.show(array);
        System.out.println("是否有序：" + sort.isSorted(array));

        sort.time(array.clone());

        sort = new InsertionSort<>();
        sort.time(array);
    }
}
